

//构造函数
function Girl(option) {
    this._init(option);
}
//原型函数
Girl.prototype = {
    constructor:Girl,
    _init:function (option) {//属性
        this.imgSrc = option.imgSrc;
        this.sWidth = option.sWidth || 256;
        this.sHeight = option.sHeight || 256;
        this.x = option.x || 200;
        this.y = option.y || 200;
        this.width = option.width || 256;
        this.height = option.height || 256;
        
        this.dir = option.dir || 0; //方向
        this.duration = option.duration　||200;//动画时间
    },

    //绘制
    render:function (ctx) {
        //备份指针
        var self = this;//girl对象

        var image = new Image();
        image.src = this.imgSrc;
        //加载图片
        image.onload = function () {
            var index = 0;
            //定时器
            setInterval(function () {
                //清屏
                ctx.clearRect(self.x, self.y, self.width, self.height);
                //截图
                ctx.drawImage(image, index * self.sWidth, self.dir * self.sHeight, self.sWidth, self.sHeight, self.x, self.y, self.width, self.height);
                index++;
                index %= 8;//循环起来
            } , self.duration);
        }

    },
    
    //改变方向
    changDir:function (dir) {
        this.dir = dir;
    }


    
};
